package demo.util;

import java.util.Map;
import java.util.TreeMap;

public enum MarketNameEnum {
    MATCH_ODDS("Match Odds", 0),
    CORRECT_SCORE("Correct Score", 0),
    OVER_UNDER("Over/Under", 0),
    OVER_UNDER_0_5("Over/Under 0.5 Goals", 0),
    OVER_UNDER_1_5("Over/Under 1.5 Goals", 1),
    OVER_UNDER_2_5("Over/Under 2.5 Goals", 2),
    OVER_UNDER_3_5("Over/Under 3.5 Goals", 3),
    OVER_UNDER_4_5("Over/Under 4.5 Goals", 4),
    OVER_UNDER_5_5("Over/Under 5.5 Goals", 5),
    OVER_UNDER_6_5("Over/Under 6.5 Goals", 6),
    OVER_UNDER_7_5("Over/Under 7.5 Goals", 7),
    OVER_UNDER_8_5("Over/Under 8.5 Goals", 8),
    TOTAL_GOALS("Total Goals", 0),
    HALF_TIME("Half Time", 0),
    HALF_TIME_SCORE("Half Time Score", 0),
    NEXT_GOAL("Next Goal", 0),
    DRAW_NO_BET("DRAW NO BET", 0);
    private String code;
    private int maxPossibleGoals = 0;

    private MarketNameEnum(String code, int maxPossibleGoals) {
        this.code = code;
        this.maxPossibleGoals = maxPossibleGoals;
    }
//
//    public String toString() {
//        return code;
//    }

    public int getMaxPossibleGoals() {
        return maxPossibleGoals;
    }

    public String getName() {
        return name();
    }

    public String getCode() {
        return code;
    }

    public static MarketNameEnum fromString(String name)
    {
        for(MarketNameEnum m : MarketNameEnum.values()) {
            if(name.equalsIgnoreCase(m.code)) {
                return m;
            }
        }
        throw new IllegalArgumentException("There is no value with code '" + name + "' in MarketNameEnum");
    }

    public Map<Integer, MarketNameEnum> getMarketsSortedByMaxPossibleGoalsAsc(){
        Map<Integer, MarketNameEnum> s = new TreeMap<Integer, MarketNameEnum>();
        for (MarketNameEnum m : MarketNameEnum.values()){
            if (m.getName().startsWith("OVER_UNDER"))
                s.put(m.getMaxPossibleGoals(), m);
        }
        return s;
    }
}